﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows.Controls;
using System.Globalization;
using QuickZip.UserControls;

namespace StudioEditorTest.CodeEditor
{
	public class WidthConverter : IMultiValueConverter
	{
		#region IMultiValueConverter Members

		public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
		{
			if (values.Length == 0) return 0;

			ListView listView = values[0] as ListView;
			if (listView == null) return 0;

			ItemsPresenter p = UITools.FindVisualChild<ItemsPresenter>(listView);

			GridView view = listView.View as GridView;
			if (view == null) throw new NotImplementedException();

			double actualWidths = 0;
			for (int i = 0; i < view.Columns.Count - 1; i++)
			{
				actualWidths += view.Columns[i].ActualWidth;
			}

			return (p.ActualWidth - actualWidths - 2);
		}

		public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
		{
			throw new NotImplementedException();
		}

		#endregion
	}
}
